{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c34cf7fd",
   "metadata": {},
   "source": [
    "# 数据归一化处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2e4c5d2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "52f5821e",
   "metadata": {},
   "source": [
    "## 最值归一化 Normalization"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10a3f8bf",
   "metadata": {},
   "source": [
    "(x - 最小值) / (最大值 - 最小值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8252f9e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.random.randint(0, 100, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "eafd1745",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.34343434, 0.16161616, 0.78787879, 0.54545455, 0.34343434,\n",
       "       0.17171717, 0.74747475, 0.66666667, 0.44444444, 0.01010101,\n",
       "       0.01010101, 0.8989899 , 0.78787879, 0.26262626, 0.83838384,\n",
       "       0.80808081, 0.5959596 , 0.52525253, 0.95959596, 0.4040404 ,\n",
       "       0.76767677, 0.81818182, 0.16161616, 0.25252525, 0.82828283,\n",
       "       1.        , 0.03030303, 0.37373737, 0.38383838, 0.25252525,\n",
       "       0.14141414, 0.18181818, 1.        , 0.6969697 , 0.54545455,\n",
       "       0.32323232, 0.13131313, 0.26262626, 0.24242424, 0.64646465,\n",
       "       0.36363636, 0.05050505, 0.65656566, 0.64646465, 0.19191919,\n",
       "       0.44444444, 0.12121212, 0.88888889, 0.87878788, 0.41414141,\n",
       "       0.86868687, 0.06060606, 0.6969697 , 0.05050505, 0.52525253,\n",
       "       0.61616162, 0.36363636, 0.50505051, 0.1010101 , 0.55555556,\n",
       "       0.74747475, 0.41414141, 0.18181818, 0.6969697 , 0.23232323,\n",
       "       0.58585859, 0.64646465, 0.91919192, 0.98989899, 0.66666667,\n",
       "       0.16161616, 0.54545455, 0.06060606, 0.27272727, 0.46464646,\n",
       "       0.62626263, 0.67676768, 0.05050505, 0.81818182, 0.76767677,\n",
       "       0.87878788, 0.13131313, 0.31313131, 0.50505051, 0.64646465,\n",
       "       0.27272727, 0.63636364, 0.56565657, 0.83838384, 0.62626263,\n",
       "       0.03030303, 0.01010101, 0.        , 0.77777778, 0.29292929,\n",
       "       0.88888889, 0.93939394, 0.98989899, 0.44444444, 0.45454545])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(x - np.min(x)) / (np.max(x) - np.min(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1213bc48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[55, 34],\n",
       "       [58,  8],\n",
       "       [78, 50],\n",
       "       [54, 86],\n",
       "       [50, 81],\n",
       "       [44, 66],\n",
       "       [29, 79],\n",
       "       [55, 12],\n",
       "       [96, 70],\n",
       "       [99, 94]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.random.randint(0, 100, size=(50,2))\n",
    "X[:10, :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5431f55b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[55., 34.],\n",
       "       [58.,  8.],\n",
       "       [78., 50.],\n",
       "       [54., 86.],\n",
       "       [50., 81.],\n",
       "       [44., 66.],\n",
       "       [29., 79.],\n",
       "       [55., 12.],\n",
       "       [96., 70.],\n",
       "       [99., 94.]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.array(X, dtype=float)\n",
    "X[:10,:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d5cb487",
   "metadata": {},
   "source": [
    "对第一列数据做最值归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6023df8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "X[:,0] = (X[:,0] - np.min(X[:,0])) / (np.max(X[:,0]) - np.min(X[:,0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5d66508",
   "metadata": {},
   "source": [
    "对第二列数据做最值归一化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f9d8d2e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "X[:,1] = (X[:,1] - np.min(X[:,1])) / (np.max(X[:,1]) - np.min(X[:,1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2f1a1c28",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.54639175, 0.28571429],\n",
       "       [0.57731959, 0.        ],\n",
       "       [0.78350515, 0.46153846],\n",
       "       [0.53608247, 0.85714286],\n",
       "       [0.49484536, 0.8021978 ],\n",
       "       [0.43298969, 0.63736264],\n",
       "       [0.27835052, 0.78021978],\n",
       "       [0.54639175, 0.04395604],\n",
       "       [0.96907216, 0.68131868],\n",
       "       [1.        , 0.94505495]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X[:10,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6c5dca97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x15a67c6d1c0>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAVGElEQVR4nO3dXYhd13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rcevkkfoQzyces0+Z+bjmfk/Sw+fYHQ6VJ81eZ8BPgP8A/Bal42bkCZ9/hjwUGa+ApCZfe93kz4n8PaICODnGQX0c902sz2Z+Q1GfbiU1uNXyQH9UgdPr/eaPllvfz7J6H/4PluzzxExB/wxcD91aPI+/yrwzoj4t4h4KiLu7Kx1k9Gkz18Bfp3R8ZXPAH+amT/tpnlT0Xr8anTAxZS0djh1jzTuT0T8PqOA/tsTbdHkNenzl4F7M/PN0eCt95r0+TLgt4CPADPAf0TEE5n50qQbNyFN+rwX+DbwYeBXgH+JiG9m5v9NuG3T0nr8KjmgD/Fw6kb9iYj3Al8Dbs7MH3TUtklp0ud54MGlYH4lcEtEnMvMo520sH1NP9uvZ+YbwBsR8Q3gOqCvAb1Jn+8CDucowXwiIr4L/BrwX900sXOtx6+SUy5DPJx6zT5HxDbgIeATPR6tLbdmnzNzR2Zuz8ztwN8Dn+pxMIdmn+1/BH4nIi6LiLcBHwBe6LidbWrS51cYzUiIiHcDO4GXO21lt1qPX8WO0HOAh1M37PPngHcBX10asZ7LHu9U17DPVWnS58x8ISK+DjwN/BT4WmaOLX/rg4bv8xeAv46IZxilI+7NzN5uqxsRfwvcCFwZESeBzwOXw+Til7f+S1IlSk65SJLWwYAuSZUwoEtSJQzoklQJA7okVcKALkmVMKBLUiX+Hyj86LBSGu+NAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[:,0], X[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03f2ae55",
   "metadata": {},
   "source": [
    "第一列平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c017f269",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.4969072164948454"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X[:,0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5a10810",
   "metadata": {},
   "source": [
    "第一列方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "28a7b56c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2928270622457266"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X[:,0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee517c6a",
   "metadata": {},
   "source": [
    "## 均值方差归一化 Standardization"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2843ee2",
   "metadata": {},
   "source": [
    "(x - 平均值) / 方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "edac43f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.random.randint(0, 100, (50, 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d697f9a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "X2 = np.array(X2, dtype=float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2558f75f",
   "metadata": {},
   "outputs": [],
   "source": [
    "X2[:,0] = (X2[:,0] - np.mean(X2[:,0])) / np.std(X2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "935e7607",
   "metadata": {},
   "outputs": [],
   "source": [
    "X2[:,1] = (X2[:,1] - np.mean(X2[:,1])) / np.std(X2[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "556259c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.87128706,  1.35896355],\n",
       "       [ 0.60319873,  0.2175416 ],\n",
       "       [ 1.57501891, -1.49459134],\n",
       "       [-1.64204099, -1.19245023],\n",
       "       [ 1.13937538,  1.45967725],\n",
       "       [-0.13404416, -0.82316666],\n",
       "       [ 0.        ,  1.15753615],\n",
       "       [ 1.54150787, -0.52102555],\n",
       "       [ 0.56968769, -0.05102828],\n",
       "       [ 1.0723533 , -1.39387763]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X2[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "d2d94d85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x15a68f6cfd0>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAVLUlEQVR4nO3dXYxdV3nG8eep60gjhDSknnx4EmIjWRaBiJqODKmlyq1SnLiRbFyihhvSCskKbS56UauDkKDqTdzmpgVSUhdFkAuSIoEnVuNgEiwUVCko4zghCcHFDaGZGSseQA5FtUpi3l6cM80wOZ+zv/f6/6TRnI+ts5b2nPPOOmu9692OCAEA2u83qu4AAKAcBHwASAQBHwASQcAHgEQQ8AEgEb9ZdQcG2bRpU2zZsqXqbgBAY5w6deonETHV67laB/wtW7Zofn6+6m4AQGPY/nG/55jSAYBEEPABIBEEfABIBAEfABJBwAeARNQ6SwcA2mju9KLuOXFGSxcuavPkhA7t2a79O6YLb5eADwAlmju9qE9+/TldfP2SJGnxwkV98uvPSVLhQZ8pHQAo0T0nzvx/sF9x8fVL+st/fUa7Dp/U3OnFwtom4ANAiZYuXOz73Mpov6igT8AHgBJtnpwY+PzF1y/pnhNnCmmbgA8AJTq0Z7smNm4YeMygbwFZsGgLACVaWZi958QZLfYJ7MO+BawXI3wAKNn+HdP699k/0D/8yW+/ZbQ/sXGDDu3ZXki7jPABoCKrR/tl5OQT8AGgQvt3TJ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e+/5akb0n6Yff35XU+773OoaQ7Jd3ZvW1J93aff04DMr5q2Pe7uuf3WUlPSvrdqvvc7deDks5Jer37Pv94g875sL6Xes4prQAAiWBKBwASQcAHgEQQ8AEgEQR8AEgEAR8AEkHAB4BEEPABIBH/B9xa+FlqoFicAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X2[:,0], X2[:,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4fc9e35b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.886579864025407e-17"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(X2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "98aa6a7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9999999999999998"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.std(X2[:,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0da636d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
